package com.xmmj.baselibrary.base.application

import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import androidx.multidex.MultiDex
import com.alibaba.android.arouter.launcher.ARouter
import com.xmmj.baselibrary.base.activity.mvvm.IBaseErrorHandle
import com.xmmj.baselibrary.utils.Logger.setDevelopMode

@SuppressLint("StaticFieldLeak")
abstract class BaseApplication : Application() {

    companion object {
        lateinit var context: Context

        var isDebug: Boolean = false

        var errorHandle: IBaseErrorHandle? = null
    }

    override fun onCreate() {
        super.onCreate()
        context = this

        //开启日志
        setDevelopMode(isDebug)

        //开启ARouter的日志
        if (isDebug) {
            ARouter.openLog()
            ARouter.openDebug()
        }
        //初始化ARouter
        ARouter.init(this)
    }

    override fun attachBaseContext(base: Context) {
        super.attachBaseContext(base)
        //方法数超过最大值，需要分包
        MultiDex.install(this)
    }

    override fun onTerminate() {
        super.onTerminate()
        //注销ARouter
        ARouter.getInstance().destroy()
    }

}